﻿using game.com;
using System.Drawing;

namespace game.spirit
{
    public class sp_block
    {
        public Color color;
        public int size;
        public Point point;

        public Direction direction;
        public Graphics graghics;

        public Color bgcolor;

        public sp_block()
        {
        }

        public sp_block(Color color, int size, Point p)
        {
            this.color = color;
            this.size = size;
            this.point = p;
        }

        public void paint(Graphics g)
        {
            SolidBrush sb = new SolidBrush(color);
            lock (g)
            {
                try
                {
                    g.FillRectangle(
                        sb,

                        point.X * this.size,
                        point.Y * this.size,
                        this.size - 1,
                        this.size - 1);
                }
                catch { }
            }
        }

        public void paint()
        {
            var g = this.graghics;

            //graghics.Clear(this.bgcolor);

            //Graphics g = Graphics.FromHdc(DesktopHandle);
            g.Clear(this.bgcolor);

            SolidBrush sb = new SolidBrush(color);
            lock (g)
            {
                try
                {
                    g.FillRectangle(
                        sb,

                        point.X * this.size,
                        point.Y * this.size,
                        this.size - 1,
                        this.size - 1);
                }
                catch { }
            }
        }

        public void Move()
        {
            Point p = new Point();

            if (this.direction == Direction.Up)
            {
                p = new Point(this.point.X, this.point.Y - 1);
            }
            else if (this.direction == Direction.Down)
            {
                p = new Point(this.point.X, this.point.Y + 1);
            }
            else if (this.direction == Direction.Left)
            {
                p = new Point(this.point.X - 1, this.point.Y);
            }
            else if (this.direction == Direction.Right)
            {
                p = new Point(this.point.X + 1, this.point.Y);
            }

            this.point = p;
            this.paint();
        }
    }
}